package week10;

import java.util.Scanner;
class ArrayUtils {
    public static double findMax (double[] arr,int begin,int end) throws IllegalArgumentException {
        if(begin>=end) {
            throw new IllegalArgumentException("begin:"+begin+" >= end:"+end);
        }
        if(begin<0) {
            throw new IllegalArgumentException("begin:"+begin+" < 0");
        }
        if(end>arr.length) {
            throw new IllegalArgumentException("end:"+end+" > arr.length");
        }
        double max = arr[begin];
        for (int i = begin+1; i <end ; i++) {
            if(arr[i]>max) {
                max = arr[i];
            }
        }
        return max;
    }
}
public class week1003 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        double[] a = new double[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        while(in.hasNextInt()) {
            int t1 = in.nextInt();
            int t2 = in.nextInt();
            double t = 0;
            try {
                t = ArrayUtils.findMax(a,t1,t2);
                System.out.println(t);
            }catch (Exception e) {
                System.out.println(e.toString());
            }

        }
        try {
            System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
        } catch (Exception e1) {
        }
    }
}